﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Eacademy.Domain.Abstractions;
using Eacademy.Domain.Models;
using Eacademy.Library.Membership;
using Eacademy.Library.Actions;

namespace Eacademy.Areas.Student.Controllers
{
    [ProfileControllerFilter]
    public class AssignmentsController : Controller
    {
        //
        // GET: /Mentor/Home/
        private const int DefaultPageSize = 10;
        private IMentorRepository _mentorRepository;
        private IAssignmentRepository _assignmentRepository;
        private ISubjectRepository _subjectRepository;
        private ILessonRepository _lessonRepository;

        public AssignmentsController(IMentorRepository mentorRepository, IAssignmentRepository assignmentRepository,ISubjectRepository subjectRepository)
        {
            _mentorRepository = mentorRepository;
            _assignmentRepository = assignmentRepository;
            _subjectRepository = subjectRepository;
        }

        CustomMembershipProvider provider = (CustomMembershipProvider)Membership.Provider;

        public ActionResult Index(int id,int mentorUserId, int? page)
        {
            int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0;
            AdminAssignmentListViewModel adminAssignmentListViewModel = new AdminAssignmentListViewModel();
            int totalcount = 0;
            List<AdminAssignmentsViewModel> assignmentList = _assignmentRepository.GetAssignmentsBySubjectId(id, mentorUserId, currentPageIndex + 1, DefaultPageSize, out totalcount);
            adminAssignmentListViewModel.AssignmentsList = assignmentList.ToPagedList(currentPageIndex, DefaultPageSize, totalcount);
            adminAssignmentListViewModel.Subject = _subjectRepository.GetSubjectBySubjectId(id);
            return View(adminAssignmentListViewModel);
        }

        public ActionResult Details(int id, int subid)
        {
            AdminAssignmentsViewModel assignment = _assignmentRepository.GetAssignmentByAssignmentId(id);
            assignment.SubjectId = subid;
            //assignment.FileList = new List<string>(assignment.Files.Split(','));
            return View("Details", assignment);
        }

        
    }

}
